import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 0
 * Date: 2023-03-10
 * Time: 13:40
 */
public class Test {

    public static void main(String[] args) {
        //int[] array = null;
        //print(array);
       /* System.out.println("前："+Arrays.toString(array));
        fun1(array);
        System.out.println("后："+Arrays.toString(array));*/
        /*int[] ret = fun2(array);
        System.out.println(Arrays.toString(ret));*/
        /*String ret = myToString(array);
        System.out.print(ret);*/
        int[] array = {1,2,3,4,5};
    }

    public static int findVal(int[] array,int key) {
        for (int i = 0; i < array.length; i++) {
            if(array[i] == key) {
                return i;
            }
        }
        return -1;
    }

    public static String myToString(int[] array) {
        if(array == null) {
            return null;
        }
        String ret = "[";
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if(i <array.length-1) {
                ret += ",";
            }
        }
        ret += "]";
        return ret;

    }

    public static int[] fun2(int[] array) {
        int a= 10;
        int b =20;
        return new int[]{a,b};
    }

    public static void fun1(int[] array) {
        int[] array2 = new int[]{2,3,4,8};
    }

    public static void print(int[] array) {
        array[0] = 9;
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }
    public static void main2(String[] args) {
        /*int[] array = {1,2,3,4,5};
        System.out.println(array[10]);*/
        /*int[] array = null;
        System.out.println(array.length);*/
        int[] array = {1,2,3,4,5};
        int[] array2 = array;
        array2[0] = 99;
        String ret = Arrays.toString(array);
        String ret2 = Arrays.toString(array2);
        System.out.println(ret);
        System.out.println(ret2);

    }

    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};
        String ret = myToString1(array);
        System.out.println(ret);
        //Arrays.toString(array);
    }

    public static String myToString1(int[] array) {
        if(array == null) {
            return null;
        }
        if(array.length == 0) {
            return "[]";
        }
        for (int i = 0; i < array.length; i++) {
            if(i == 0) {
                System.out.print("[");
            }
            System.out.print(array[i]);
            if(i <= array.length-1) {
                System.out.print(",");
            }

        }

        return "]";
    }
}
